import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/data/entities/inspec/plan_associated_tasks_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/hazard_investigation/investigation_plan/plan_unit/plan_unit_controller.dart';

/// 排查计划-单元列表
class PlanUnitPage extends StatelessWidget {
  PlanUnitPage({super.key});

  final controller = Get.put(PlanUnitController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Scaffold(
          appBar: CustomAppBar(titleText: '排查路线'),
          body: Container(
            alignment: Alignment.center,
            color: const Color(0xffF5F5F6),
            padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 20.w),
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 16.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(12),
              ),
              child: CustomEasyRefreshList<PlanAssociatedTasksEntity>(
                key: controller.globalKey,
                dataLoad: (pageIndex, pageSize, {String? search}) async {
                  return controller.getListData(pageIndex, pageSize);
                },
                enableLoad: false,
                itemBuilder: (PlanAssociatedTasksEntity item, int index) {
                  return Container(
                    padding: EdgeInsets.only(
                      top: 12.w,
                      bottom: 12.w,
                      left: 10.w,
                      right: 10.w,
                    ),
                    // margin: EdgeInsets.only(
                    //   bottom: 16.w,
                    //   right: 12.w,
                    //   left: 12.w,
                    // ),
                    decoration: BoxDecoration(
                        border: Border.all(width: 1, color: const Color(0x33587DF5)), borderRadius: BorderRadius.circular(12), color: const Color(0xFFF5F6FF)),
                    child: Column(
                      children: [
                        Align(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '${item.riskUnitName}',
                            style: TextStyle(
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ),
                        AppGaps.vGap12,
                        Row(
                          children: [
                            Column(
                              children: [
                                Text(
                                  '任务',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                  ),
                                ),
                                AppGaps.vGap4,
                                Text(
                                  '${item.taskNum}',
                                  style: TextStyle(
                                    fontSize: 16.sp,
                                    color: AppColors.font_color_blue,
                                  ),
                                ),
                              ],
                            ),
                            AppGaps.hGap50,
                            Column(
                              children: [
                                Text(
                                  '待完成',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                  ),
                                ),
                                AppGaps.vGap4,
                                Text(
                                  '${item.numberOfTasksToBeCompleted}',
                                  style: TextStyle(
                                    fontSize: 16.sp,
                                    color: AppColors.font_color_gray,
                                  ),
                                ),
                              ],
                            ),
                            const Spacer(),
                            SvgPicture.asset(
                              AppImages.icon_bar_scanning,
                              width: 20.w,
                              height: 20.w,
                              colorFilter: const ColorFilter.mode(Color(0xFF495061), BlendMode.srcIn),
                            ).clickOnce(() {
                              controller.scan(item);
                            })
                          ],
                        )
                      ],
                    ),
                  ).clickOnce(() {
                    controller.toTask(item.riskUnitId!);
                  });
                },
              ),
            ),
          ),
        );
      },
    );
  }
}
